import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter/widgets.dart';
import 'package:ls_work/res/colors.dart';
import 'package:ls_work/viewmodel/new_health/new_health_report_list_view_model.dart';

import '../../a_yyt/widget/health_record_cell.dart';
import '../../res/styles.dart';
class NewHealthReportListPage extends BaseStatefulMvvmWidget{
  @override
  State<StatefulWidget> createState()=> _NewHealthReportListState();

}

class _NewHealthReportListState extends BaseMvvmListState<NewHealthReportListViewModel,NewHealthReportListPage>{
  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return Scaffold(
      appBar: AppBar(title: Text("健康记录"),),
      body: Column(
        children: [
          Row(
            children: [
              CommonText(vm?.elder?.name,hintText: '选择长者'),
              SizedBox(width: 10,),
              Icon(vm?.elder==null?Icons.arrow_drop_down_sharp:Icons.clear,size: 17,).onTap(() {
                if(vm?.elder!=null){
                  setState(() {
                    viewModel.elder = null;
                    viewModel.requestRefresh();
                  });
                }
              })
            ],
            mainAxisSize: MainAxisSize.min,
          ).addToContainer(
            decoration: BoxDecoration(
              color: Colours.bg_color,
              borderRadius: 8.borderRadius
            ),
            alignment: Alignment.center,
            margin: EdgeInsets.symmetric(horizontal: 16,vertical: 16,),
            padding: EdgeInsets.symmetric(horizontal: 16,vertical: 12),
            width: double.infinity
          ).onTap(() {
            viewModel.chooseOld();
          }),
          loadingContentWidget.setWeight(1)
        ],
      ),
    );
  }

  @override
  Widget createItemWidget(int index) {
    return ExpansionPanelList.radio(
      expansionCallback: (int index, bool isExpanded) {
        // setState(() {
        viewModel.listItems[index].isExpanded = isExpanded;
        print(viewModel.listItems[index].isExpanded);
        // });
      },
      children: [
        ExpansionPanelRadio(
            value: viewModel.listItems[index].isExpanded??false,
            canTapOnHeader: true,
            headerBuilder: (BuildContext context, bool isExpanded) {
              return ListTile(
                title:  RichText(
                    text: TextSpan(children: [
                      TextSpan(
                          text:
                          '${viewModel.listItems[index].customerName??""}',
                          style: TextStyle(color: Colors.orange)),
                      TextSpan(
                          text:
                          '   ${viewModel.listItems[index].collectionTime??""}',
                          style: TextStyles.textDark16)
                    ])),
              );
            },
            body: HealthRecordCell(
              info: viewModel.listItems[index],
            ))
      ],
    );
  }

  @override
  bool get canPullUp => true;

  @override
  NewHealthReportListViewModel createViewModel() {
    return NewHealthReportListViewModel(context);
  }

}